package com.wechat.servlet;

import com.wechat.DAO.DaoImpl.UserDAOIpml;
import com.wechat.DAO.UserDAO;
import com.wechat.pojo.User;
import com.wechat.servlet.Utils.SearchUserInfo;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        UserDAO userDAO = new UserDAOIpml();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println(username+"--"+password);
        User user = userDAO.querySQL("select * from Users where username="+username);
        if(user!=null){
            if (user.getPassword().equals(password)){
//                登录成功代码
//                response.getWriter().write("success");
                SearchUserInfo.search(username,response);
            }else {
                //密码错误代码
                response.getWriter().write("fail");
            }
        }else {
            //用户不存在代码
            response.getWriter().write("fail");
        }
    }
}
